#include "Menu.h"
#include "MainMenu.h"
#include <allegro.h>
#include <iostream>
#include "../common/CommonResource.h"

using namespace std;

extern FONT* font;

MainMenu::MainMenu() {
    setBackground(create_bitmap(800,600));
    PALETTE p;    
    setBackground(load_bmp("graphics/MenuBackground.bmp", p));
    setFont(font);
    int xOffset = 100; //distance from left border
    
    BITMAP *item1Bitmap = load_bitmap("graphics/MainMenuButton_Return.bmp", NULL);
    BITMAP *item2Bitmap = load_bitmap("graphics/MainMenuButton_Settings.bmp", NULL);
    BITMAP *item4Bitmap = load_bitmap("graphics/MainMenuButton_Exit.bmp", NULL);


    addMenuItem(new MenuItem("Return to game", item1Bitmap,
                xOffset, Y_OFFSET, &MainMenu::callbackItem1));
    addMenuItem(new MenuItem("Settings", item2Bitmap,
                xOffset, Y_OFFSET*2, &MainMenu::callbackItem2));
    /*addMenuItem(new MenuItem("Placeholder", create_bitmap(50,150),
                xOffset, Y_OFFSET*3, &MainMenu::callbackItem3));*/
    addMenuItem(new MenuItem("Exit Game", item4Bitmap,
                xOffset, Y_OFFSET*3, &MainMenu::callbackItem4));
}

void MainMenu::callbackItem1(void) {
   cout << "Callback 1\n"; 
    /* Switches the screens */
    int as = CommonResource::getInstance()->getActiveScreen();

    CommonResource::getInstance()->getScreenManager()->setActiveScreen((as++)%2);
    blit(CommonResource::getInstance()->getScreenManager()->getActiveScreen()->draw(),screen, 0,0,0,0,800,600);
}

void MainMenu::callbackItem2(void) {
    cout << "executed callback for item 2" << endl;
}
void MainMenu::callbackItem3(void) {
    cout << "executed callback for item 3" << endl;
}

void MainMenu::callbackItem4(void) {
    /* Exit the game */
    cout << "Exiting game" << endl;
    CommonResource::getInstance()->setQuit(true); 
}


